package com.ruoyi.garbage.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.garbage.domain.SpeechClassify;
import com.ruoyi.garbage.service.ISpeechClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 语音识别记录Controller
 *
 * @author 刘哲贤
 * @date 2023-01-07
 */
@RestController
@RequestMapping("/admin/speechClassify")
public class SpeechClassifyController extends BaseController {
    @Autowired
    private ISpeechClassifyService speechClassifyService;

    /**
     * 查询语音识别记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:speechClassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(SpeechClassify speechClassify) {
        startPage();
        List<SpeechClassify> list = speechClassifyService.selectSpeechClassifyList(speechClassify);
        return getDataTable(list);
    }

    /**
     * 导出语音识别记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:speechClassify:export')")
    @Log(title = "语音识别记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpeechClassify speechClassify) {
        List<SpeechClassify> list = speechClassifyService.selectSpeechClassifyList(speechClassify);
        ExcelUtil<SpeechClassify> util = new ExcelUtil<SpeechClassify>(SpeechClassify.class);
        util.exportExcel(response, list, "语音识别记录数据");
    }

    /**
     * 获取语音识别记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:speechClassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(speechClassifyService.selectSpeechClassifyById(id));
    }

    /**
     * 新增语音识别记录
     */
    @PreAuthorize("@ss.hasPermi('admin:speechClassify:add')")
    @Log(title = "语音识别记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpeechClassify speechClassify) {
        return toAjax(speechClassifyService.insertSpeechClassify(speechClassify));
    }

    /**
     * 修改语音识别记录
     */
    @PreAuthorize("@ss.hasPermi('admin:speechClassify:edit')")
    @Log(title = "语音识别记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpeechClassify speechClassify) {
        return toAjax(speechClassifyService.updateSpeechClassify(speechClassify));
    }

    /**
     * 删除语音识别记录
     */
    @PreAuthorize("@ss.hasPermi('admin:speechClassify:remove')")
    @Log(title = "语音识别记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(speechClassifyService.deleteSpeechClassifyByIds(ids));
    }
}
